package cn.org.guhao.practice.zk.configuration;

import cn.org.guhao.practice.zk.properties.CuratorProperties;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ZkConfiguration {

    @Bean(initMethod = "start")
    public CuratorFramework curatorFramework(CuratorProperties properties) {
        return CuratorFrameworkFactory.newClient(
                properties.getConnectString(),
                properties.getSessionTimeoutMs(),
                properties.getConnectionTimeoutMs(),
                new RetryNTimes(properties.getRetryCount(), properties.getElapsedTimeMs()));
    }

}
